import Vue from 'vue'
import Router from 'vue-router'
import user from '@/view/user'
import topic from '@/view/topic'

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'user',
      component: user
    },
    {
      path: '/topic',
      name: 'topic',
      component: topic
    }
  ],
  beforeEnter: (to, from, next) => {
    let token = Vue.cookie.get("token");
    alert(1);
    if (!token || !/\S/.test(token)) {
      Vue.cookie.delete('token')
      next({ name: 'login' })
    }
    next()
  },
  create() {
    alert(1)
    // let token = Vue.cookie.get("token");
    // if (!token || !/\S/.test(token)) {
    //   Vue.cookie.delete('token')
    //   next({ name: 'login' })
    // }
    // next()
  },
})



